home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 6.2 KB | 294 lines | [TEXT/MSET] |
- \ 25Dec93 DBH made font the superclass
- \ 28Oct94 dbh updated to 2.5 syntax
-
- (*
-
- Note that we normally would subclass from te, as we do in tebox and tescroll.
- A te is a selection object and perhaps is one of the best examples of the
- advantages of using the selection framework. We can have as many te objects
- as we wish in a window and they will all behave as expected in that each
- must first be selected with the mouse and then keystrokes may be received.
- The selection framework does not allow passing keystrokes to more than one
- object at a time, keystrokes are only passed to the currently selected object.
-
- Also note that the clipboard is supported (automatically).
-
- *)
-
-
- :CLASS te super{ font }
- \ some ivars for initial values
- rect+ destRect
- rect+ viewRect
- handle TEHandle
-
-
-
- \ ***** SAFE METHODS (can be called without concern to being alive)
-
- :m alive?: ( -- b )
- nil?: TEHandle not ;m
-
- :m view: ( -- l t r b )
- get: viewRect ;m \ we always maintain this, so will work when alive
-
- :m setview: { l t r b -- }
- l t r b put: viewRect
- alive?: self
- IF
- l t r b ptr: TEHandle setview: terec
- THEN ;m
-
- :m dest: ( -- l t r b )
- get: destRect ;m \ we always maintain this, so will work when alive
- \ ???? does this really work when alive?? \ 24May93 DBH
-
- :m setdest: { l t r b -- }
- l t r b put: destRect
- alive?: self
- IF
- l t r b ptr: TEHandle setdest: terec
- THEN ;m
-
- :m setrects: { l t r b -- }
- l t r b setdest: self
- l t r b setview: self ;m
-
- :m classinit:
- 20 20 50 50 setdest: self
- 20 20 50 50 setview: self
- ;m
-
- :m moveto: { l t -- }
- l t moveto: destRect
- l t moveto: viewrect
- alive?: self
- IF
- l t ptr: TEHandle moveto: teRec \ note message to class
- THEN
- ;m
-
- :m move: { dx dy -- }
- dx dy move: destRect
- dx dy move: viewRect
- alive?: self
- IF
- dx dy ptr: TEHandle move: teRec \ note message to class
- THEN
- ;m
-
- :m hit?: \ ( -- b )
- where: theMouse
- viewRect PtInRect ;m
-
- :m focus?: ( -- t ) true ;m
-
- :m alwaysActive?: ( -- f ) false ;m
-
- :m new: ( wptr -- ) drop \ stay consistent with select prototcol
- getnew: super> font
- set: super> font \ 28Dec93 dbh \ 29Oct94 dbh
- 0 \ space for returned handle
- destRect
- viewRect
- call TENew
- put: TEHandle
- ;m
-
-
- \ *** UNSAFE METHODS (must only be called when alive)
- :m handle: ( -- tehandle )
- get: TEHandle ;m
-
- :m ptr: ( -- terec )
- ptr: TEHandle ;m
-
- :m noWrap:
- ptr: self noWrap: teRec ;m
-
- :m setlineHeight: ( n -- )
- ptr: TEHandle setlineHeight: teRec ;m
-
- :m LINEHEIGHT: ( -- n )
- ptr: TEHandle lineHeight: teRec ;m
-
- :m cut:
- get: TEHandle call TECut
- todesk drop ;m \ not looking at error
-
- :m copy:
- get: TEHandle call TECopy
- todesk drop ;m \ not looking at error
-
- :m paste:
- fromdesk IF exit THEN \ out if error
- get: TEHandle call TEPaste ;m
-
- :m clear:
- get: TEHandle call TEDelete ;m
-
- :m draw:
- \ addr: viewRect call ClipRect \ 01May93 DBH
- clear: viewRect \ per IM I-387, call EraseRect
- viewRect get: TEHandle call TEUpdate
- ;m
-
- :m size: ( -- len ) \ returns the length of the text
- ptr: TEHandle size: teRec ;m \ note message to class
-
- :m textaddr: ( -- $addr ) \ addr of the first char of the TE text
- 0 get: TEHandle call TEGetText @ ( $addr ) ;m
-
- :m get: ( -- $addr len )
- textaddr: self
- size: self ;m
-
- :m put: ( $addr len -- )
- get: TEHandle call TESetText
- draw: self
- ;m
-
- :m insert: ( $addr len -- )
- get: TEHandle call TEInsert
- ;m
-
- :m activate:
- get: TEHandle call TEActivate ;m
-
- :m deactivate:
- get: TEHandle call TEDeactivate ;m
-
- :m release:
- get: TEHandle call TEDispose
- clear: TEHandle ;m
-
- :m idle:
- get: TEHandle call TEIdle
- where: theMouse
- viewRect PtInRect
- IF ibeamcurs
- ELSE initCursor
- THEN
- ;m
-
- :m click:
- where: theMouse pack ( point)
- mods: fevent $ 200 and makeint \ extend if shift key
- get: TEHandle
- call TEclick
- ;m
-
- :m key: \ ( char -- )
- makeint
- get: TEHandle
- call TEKey ;m
-
- :m select: ( start end -- ) \ hilites the given range
- get: TEHandle call TESetSelect ;m
-
- :m selectAll: \ hilites all of the text
- 0 ( start)
- size: self ( end)
- select: self ;m
-
- :m selStart: ( -- n )
- ptr: TEHandle selStart: terec ;m
-
- :m selEnd: ( -- n )
- ptr: TEHandle selEnd: terec ;m
-
- \ :m addrLineStart: ( -- addr )
- \ ptr: TEHandle addrLineStart: terec ;m
-
- :m lastchar: ( -- char ) \ return last character in TE
- textaddr: self size: self 1- + c@ ;m
-
- 0 value kludge
-
- :m #lines: ( -- n)
- 0 -> kludge
- ptr: TEHandle #lines: teRec \ note message to class
- lastchar: self ret = IF -1 -> kludge 1+ THEN \ kludge Apple line numbering scheme!!
- ;m
-
- \ given the zero-based line number, return the character# of the start of that line
- :m at: { n -- linestart }
- n kludge + 1 + #lines: self > abort" TE linestart index out of range"
-
- ptr: TEHandle addrLineStart: teRec n 2 * + w@ ;m
-
- :m GETPOINT: { offset -- x y } \ given the char offset into the text, return the
- \ corresponding x y location See IM V-269.
- 0 offset makeint get: TEHandle call TEGetPoint unpack ;m
-
- :m currentLine: ( -- n ) \ **
- selend: self GETPOINT: self ( x y ) nip ( cursor.y )
- ptr: TEHandle ( dest) gettopy: rect - ( cursor.y - dest.top )
-
- lineheight: self / 1-
-
- selend: self size: self = \ true if at last char
- size: self and \ and if not an empty size
- IF
- lastchar: self ret =
- IF \ uh-oh, handle special case where last char is a ret
- 1+
- THEN
- THEN
- ;m
-
- :m getLine: { \ l -- addr len }
- size: self 0= IF pad 0 exit THEN \ return nil and get out if no text
- currentLine: self -> l
- #lines: self 1 - l =
- IF \ we are on the last line
-
- lastchar: self \ **
- ret =
- IF \ we are on the last line AND just beyond a carriage return!
- pad 0 exit \ return nil and get out here
- THEN
-
- textaddr: self l at: self + ( addr) \ **
- size: self
- l at: self - ( len)
-
- ELSE
-
- textaddr: self l at: self + ( addr) \ **
-
- l 1 + at: self
- l at: self - 1 - ( len)
- THEN
- ;m
-
- :m getselect: ( -- addr len ) \ returns hilited selection
- ptr: TEHandle getselect: terec ;m
-
-
- :m LINEEND: { \ len pos -- pos } \ return the character position corresponding to the
- \ end of the last line of the current selection.
- selend: self size: self =
- IF \ we are at the end of the text
- size: self
- ELSE
- currentline: self at: self ( linestart ) -> pos
- getline: self nip -> len
- pos len +
- THEN ;m
-
- ;CLASS
-
- endload
-
- *** EXAMPLE USE
-
-
- selwindow w
- test: w
-
- te t
- t add: w
-
- " Hi Bye" insert: t
-